/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package service;


import bean.usuario;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.Statement;

/**
 *
 * @author Hugo
 */
public class usuarioService {


   public static boolean validaLogin(Connection conn, String user, String pass) throws Exception {


        String laConsulta = "SELECT * FROM usuarios WHERE username = '" + user + "' and password ='" + pass + "' ";

        Statement stmtConsulta = (Statement) conn.createStatement();
        ResultSet rs = stmtConsulta.executeQuery(laConsulta);

        boolean var = false;

        if (rs.absolute(1)) {
            var = true;
        }

        stmtConsulta.close();

        return var;
    }

public static usuario datosUsuario(Connection conn, String pass) throws Exception {


        String laConsulta = "SELECT * FROM usuarios WHERE  password ='" + pass + "' ";

        Statement stmtConsulta = (Statement) conn.createStatement();
        ResultSet rs = stmtConsulta.executeQuery(laConsulta);

        usuario usu=null;
        
        if (rs.next()) {
           usu = new usuario();
           usu.setApellido(rs.getString("apellido"));
           usu.setNombre(rs.getString("nombre"));
           usu.setUsername(rs.getString("username"));
           usu.setPassword(pass);
        }

        stmtConsulta.close();

        return usu;
    }

}
